package nix.json;

import java.util.ArrayList;
import java.util.List;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import org.junit.Test;

public class Demo1 {

	@Test
	public void fun1() {
		JSONObject map = new JSONObject();
		map.put("name", "zhangsan");
		map.put("age", 18);
		map.put("gender", "male");
		System.out.println(map.toString());
	}

	@Test
	public void fun2() {
		Person p = new Person("zhangsan", 18, "male");
		JSONObject map = JSONObject.fromObject(p);
		System.out.println(map.toString());
	}

	@Test
	public void fun3() {
		Person p1 = new Person("zhangsan", 18, "male");
		Person p2 = new Person("lisi", 23, "female");
		JSONArray list = new JSONArray();
		list.add(p1);
		list.add(p2);
		System.out.println(list);
	}

	@Test
	public void fun4() {
		List<Person> ps = new ArrayList<Person>();
		ps.add(new Person("zhangsan", 18, "male"));
		ps.add(new Person("lisi", 23, "female"));
		JSONArray list = JSONArray.fromObject(ps);
		System.out.println(list.toString());
	}
}
